package com.hw.one.collect.base;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2017/9/19.
 */
@Component
public class BaseContextUtil implements ApplicationContextAware {
    protected static ApplicationContext context;

    public BaseContextUtil() {
    }
    @SuppressWarnings("static-access")
    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        BaseContextUtil.context = context;
    }

    public static Object getBean(String beanName) {
        try {
            return context.getBean(beanName);
        } catch (Exception var2) {
            var2.printStackTrace();
            return null;
        }
    }
}
